package cn.ac.jaas.isc.vegetable.common.security.component;

import cn.ac.jaas.isc.vegetable.common.core.util.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;

/**
 * @author 张高昌
 * @date 2022/4/23 14:12
 * @description: 功能描述
 */
@Slf4j
@EnableScheduling
@ConditionalOnBean(AuthorizationServerConfigurerAdapter.class)
public class VegetableTokenStoreCleanSchedule {

    @Scheduled(cron = "@hourly")
    public void doMaintenance() {
        VegetableRedisTokenStore tokenStore = SpringContextHolder.getBean(VegetableRedisTokenStore.class);
        long maintenance = tokenStore.doMaintenance();
        log.debug("清理Redis ZADD 过期 token 数量: {}", maintenance);
    }
}
